<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of genReporte
 *
 * @author mini
 */
class Kpi extends CI_Controller {

    public function __construct() {
        parent::__construct();
        global $admin, $data;
        #Cargamos datos del administrador
        $admin = $this->session->userdata('admin');
        $this->verificacion_acceso($admin);
        $admin['place'] = 'kpi';
        $this->output->enable_profiler(FALSE);
    }

    public function index() {
        global $admin, $data;

        $data['graphComp'] = $this->cc_model_b->dataGraphCom();
        $data['empresa'] = $this->comparativa();
        $this->load->view('template/header', $admin);
        $this->load->view('template/open_content_container');
        $this->load->view('menu/menu_admin', $data);
        $this->load->view('genReporte/kpi/content');
        $this->load->view('template/close_content_container');
        $this->load->view('template/footer');
    }

    private function comparativa() {
        $m = array();
        $empresa = $this->cc_model_a->lista_empresas();
        foreach ($empresa as $v) {
            $t = $this->cc_model_a->promXdivEmpresa($v->e_empresa_id);
            $str = "";
            foreach ($t as $e) {
                $prom = $e->prom * 10;
                $str.='{date:"' . $e->ct_uacceso . '", 
                        value:' . $e->prom . ',
                        volume:' . $prom . '},';
            }
            $str = trim($str, ',');
            $m['emp_' . $v->e_empresa_id] = $str;
        }
        return $m;
    }

    /**
     * Funcion que se encarga de verificar que 
     * se logueara antes
     */
    public function verificacion_acceso($admin) {
        if ($admin['ta_tipo_administrador_id'] != 1) {
            redirect('home');
        }
    }

}
